package admin.controllers;

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import admin.data.UserData;

import models.UserModel;


import debugs.UserDebug;


public class DeleteUserServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException {
	response.setContentType("text/html");
	String path = ((HttpServletRequest) request).getRequestURI();
	String username = "";
	try {
		username = URLDecoder.decode(path.toLowerCase().replaceAll("/admin/delete-user/", ""),"UTF-8");
	} catch (Exception e) {
		response.sendRedirect("/admin/list-user");
	}
	try {
		UserData uData = new UserData();
		UserModel user = uData.getUser(username);
		uData.delete(user);
		UserDebug.debugWeb(user, response);
	} catch (Exception e) {
		// TODO: handle exception
	}
	response.sendRedirect("/admin/list-user");
}
}
